<template>
  <el-dialog
    v-model="dialogVisible"
    width="80vw"
    :title="t('warehouse.inventoryTotal')"
    :before-close="closeDialog"
  >
    <div>
      <el-table
        class="m-t-10px"
        :data="dataList"
        border
        ref="tableRef"
        :cell-style="{ textAlign: 'center' }"
        :header-cell-style="{ textAlign: 'center' }"
        max-height="calc(70vh - 170px)"
      >
        <el-table-column
          :label="t('warehouse.inventoryId')"
          prop="inventory_id"
          :show-overflow-tooltip="true"
          width="100"
          align="center"
          header-align="center"
        />
        <el-table-column
          :label="t('warehouse.businessType')"
          prop="business"
          align="center"
          header-align="center"
          min-width="120"
        />
        <el-table-column
          :label="t('common.operator')"
          prop="creator_name"
          align="center"
          header-align="center"
          min-width="120"
        />
        <el-table-column
          :label="t('common.operateTime')"
          prop="create_time"
          align="center"
          header-align="center"
          min-width="150"
        />
        <el-table-column
          :label="t('warehouse.operateQuantity')"
          prop="number"
          align="center"
          header-align="center"
          min-width="120"
        />
        <el-table-column
          :label="t('common.remark')"
          prop="remark"
          align="center"
          header-align="center"
          min-width="150"
          :show-overflow-tooltip="true"
        />
      </el-table>
    </div>
  </el-dialog>
</template>
<script setup lang="ts">
import { useI18n } from '@/hooks/web/useI18n'
import { warehouseCountShippedOrderApi, warehouseCountTotalQtyApi } from '@/api/warehouse/index'

const { push } = useRouter()
const props = defineProps({
  shopInfo: {
    type: Object,
    default: () => {}
  }
})
const { t } = useI18n()
const dialogVisible = ref<boolean>(false)
//获取数据
const dataList = ref<any>([])
const getData = async (params?: any) => {
  console.log('DialogTotal getData 接收到的参数:', params)
  console.log('props.shopInfo:', props.shopInfo)

  // 使用传递的参数，如果没有传递则使用 props 中的默认值
  const requestParams = params || {
    product_id: props.shopInfo.product_id,
    warehouse_id: props.shopInfo.warehouse_id,
    is_futures: props.shopInfo.is_futures,
    arrival_date: props.shopInfo.arrival_date
  }

  console.log('最终发送的请求参数:', requestParams)

  try {
    const resp = await warehouseCountTotalQtyApi(requestParams)
    if (resp && resp.data) {
      dataList.value = resp.data.list || []
    } else {
      dataList.value = []
    }
  } catch (error) {
    console.error('获取总数数据失败:', error)
    dataList.value = []
  }
}
const closeDialog = () => {
  dialogVisible.value = false
  console.log('关闭', dialogVisible.value)
}
// 移除 handleJump 函数，因为不再需要跳转功能
defineExpose({
  dialogVisible,
  getData
})
</script>
<style lang="less" scoped></style>
